﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace MusicStore.WebService.Helpers
{
	public static class ImageHelper
	{
		public static string BuildImagePath(HttpContext context, int imageId)
		{
			string path = context.Server.MapPath(string.Format("~/images/{0}.jpg", imageId));
			return path;
		}

		public static string BuildImageUri(HttpContext context, int imageId)
		{
			Uri uri = context.Request.Url;
			string path = BuildImagePath(context, imageId);
			if (System.IO.File.Exists(path))
				return uri.AbsoluteUri.Replace(uri.AbsolutePath, string.Format("/images/{0}.jpg", imageId));

			// use the default one (replace with a not available image)
			return uri.AbsoluteUri.Replace(uri.AbsolutePath, "/images/0.jpg");
			//Random rnd = new Random();
			//return uri.AbsoluteUri.Replace(uri.AbsolutePath, string.Format("/images/test/{0}.jpg", rnd.Next(1, 4)));
			// albumSummary.Image = "http://localhost.:50671/Images/1.jpg";
		}
	}
}
